package Power;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URLClassLoader;

import javax.imageio.ImageIO;

import Main.SpaceGame;
import World.TileType;

public class SolarPanel extends Generator
{
	BufferedImage sprite = null;
	
	public SolarPanel(int x, int y, SpaceGame main) 
	{
		super(x, y, main);
		width = 1;
		height = 1;
		nodesSupported = 3;
		this.x = x;
		this.y = y;
		
		try {
			sprite = ImageIO.read(URLClassLoader.getSystemResource("Resources/"+"SolarPanel.png"));
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		setText();
	}

	@Override
	public void draw(Graphics g) 
	{
		g.drawImage(sprite, x*10, y*10, null);
		setText();
	}
	
	public boolean checkSupport()
	{
		boolean hasSupport = false;
		for(int dx = -1; dx<=1;dx++)
		{
			for(int dy = -1; dy<=1;dy++)
			{
				if (main.world.tiles[x+dx][y+dy].getType() == TileType.Hull)
				{
					hasSupport = true;
				}
				for(Generator g:main.powerManager.generatorList)
				{
					if (!(g.equals(this)) && g.getX() == x+dx && g.getY() == y+dy)
						hasSupport = true;
				}
			}
		}
		return hasSupport;
	}

	@Override
	public void setText() 
	{
		textColorIndex = 2;
		
		colors.add(Color.cyan);
		colors.add(Color.cyan);
		text.add("");
		text.add(getName());
		
		colors.add(Color.cyan);
		colors.add(Color.cyan);
		text.add("");
		text.add("");
	}

	@Override
	public String getName() 
	{
		return "Solar Panel";
	}
	
}
